<template>
    <div class="card p-2">
        <div class="card-body">
            <div class="row">
                <div class="col-4">
                    <img class="img-fluid" src="https://y.qq.com/music/photo_new/T002R300x300M000003CS0lX1DwEcN_2.jpg?max_age=2592000" alt="profile"/>
                </div>
                <div class="col-8">
                    <div class="username">{{ full_name }}</div>
                    <div class="fans">粉丝数：{{ user.followers }}</div>
                    <button v-if="!user.is_followed" @click="follow" class="btn btn-primary">+关注</button>
                    <button v-if="user.is_followed" @click="unfollow" class="btn btn-secondary">取消关注</button>
                </div>
            </div>
            
        </div>
    </div>
</template>

<script>
import { computed } from 'vue'

    export default {
        name: "UserProfileInfo",
        props: {
            user: {
                type: Object,
                required: true,
            }
        },
        setup(props, context) {
            let full_name = computed(() => props.user.first_name + ' ' + props.user.last_name);

            const follow = () => {
                context.emit("follow");
            }

            const unfollow = () => {
                context.emit("unfollow");
            }

            return {
                full_name,
                follow,
                unfollow,
            };
        }
    }
    
</script>

<style scoped>
img {
    border-radius: 50%;
}

.username {
    font-weight: bold;
}

.fans {
    font-size: 12px;
    color: gray;
}

button {
    font-size: 12px;
    padding: 2px 4px
}
</style>